import {Descriptions, Modal} from 'antd';
import React from 'react';
import {fullDownloadFileUrl} from "@/services/system/file";
import {API} from "@/services/typings";

interface SettingDetailProps {
  data: API.ISetting;
  visible: boolean;
  onClose: () => void;
}

const SettingDetail: React.FC<SettingDetailProps> = ({data, visible, onClose}) => {
  const getValueLabel = (value: any, map: Record<string, string>) => {
    return map[value] || value || '-';
  };

  const settingTypeMap = {
    'string': '字符串',
    'number': '数值',
    'boolean': '布尔值',
    'json': 'JSON',
    'file': '文件',
  };

  return (
    <Modal
      title="系统设置详情"
      width={800}
      open={visible}
      onCancel={onClose}
      footer={null}
      destroyOnClose
    >
      <Descriptions column={2} bordered>
        <Descriptions.Item label="ID">{data.id}</Descriptions.Item>
        <Descriptions.Item label="设置名称">{data.name}</Descriptions.Item>
        <Descriptions.Item label="配置键">{data.settingKey}</Descriptions.Item>
        <Descriptions.Item label="配置类型">{getValueLabel(data.settingType, settingTypeMap)}</Descriptions.Item>
        <Descriptions.Item label="配置值" span={2}>
          {data.settingType === 'file' ? (
            <a href={fullDownloadFileUrl(data.settingValue || '')} target="_blank" rel="noopener noreferrer">
              查看文件
            </a>
          ) : data.settingValue}
        </Descriptions.Item>
        <Descriptions.Item label="配置说明" span={2}>
          {data.description || '-'}
        </Descriptions.Item>
        <Descriptions.Item label="创建人">{data.createdBy}</Descriptions.Item>
        <Descriptions.Item label="创建时间">{data.createdAt}</Descriptions.Item>
        <Descriptions.Item label="更新人">{data.updatedBy || '-'}</Descriptions.Item>
        <Descriptions.Item label="更新时间">{data.updatedAt || '-'}</Descriptions.Item>
      </Descriptions>
    </Modal>
  );
};

export default SettingDetail;
